


//
//  ShangHomeTableViewCell.m
//  GoShops
//
//  Created by zcj on 15-11-23.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "ShangHomeTableViewCell.h"
#import "Grouble.h"
#import "MyCollection.h"
#import "HomeServiceModel.h"

@interface ShangHomeTableViewCell()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,weak)UICollectionView * cooection;

@end
@implementation ShangHomeTableViewCell

+(instancetype)ShangHomeTableViewCell:(UITableView *)tableView
{
    static NSString *menuID = @"shanghome";
    ShangHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:menuID];
    if (cell == nil) {
        cell = [[ShangHomeTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:menuID];
    }
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initViews];
        // Initialization code
    }
    return self;
}
- (void)initViews
{
    CGFloat margen = 10;
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    CGFloat itemLayoutW = ScreenWidth / 3;
    CGSize cccc = {itemLayoutW,100};
    // 设置周边距离
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    // 设置每一个layout的匡高
    layout.itemSize = cccc;
    // 设置每行距离
    layout.minimumLineSpacing = 20;
    
    CGFloat collectionX = margen;
    CGFloat collectionY = margen;
    CGFloat collectionW = ScreenWidth;
    CGFloat collectionH = 240;
    
    
    UICollectionView * cooection = [[UICollectionView alloc]initWithFrame:CGRectMake(collectionX, collectionY, collectionW, collectionH) collectionViewLayout:layout];
    
    cooection.backgroundColor = [UIColor whiteColor];
    
    cooection.delegate = self;
    cooection.dataSource = self;
    // 不显示滚动
    cooection.showsHorizontalScrollIndicator = NO;
    
    [cooection registerClass:[MyCollection class] forCellWithReuseIdentifier:@"mycollection"];
    [self addSubview:cooection];
    self.cooection = cooection;
    

}
- (void)setHomeServiceArray:(NSMutableArray *)homeServiceArray
{
    _homeServiceArray = homeServiceArray;
    
    [self.cooection reloadData];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyCollection * cell = [MyCollection MyCollection:collectionView cellForItemAtIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor redColor];
    if (_homeServiceArray.count != 0) {
        HomeServiceModel * model = _homeServiceArray[indexPath.row];
        cell.homeModel = model;
    }
    
    
    //cell.homeServiceArray = _homeServiceArray;
    return cell;
    
}
// 选中行,通知代理
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if([self.delegate respondsToSelector:@selector(ShangHomeTableViewCellClick:)]){
        ZCJLog(@"djklfkldfjk");
        [self.delegate ShangHomeTableViewCellClick:indexPath];
    }
    ///ZCJL
    //[self.delegate ShangHomeTableViewCellClick:indexPath];
//    if ([self.delegate respondsToSelector:@selector(ShangHomeTableViewCellClick:)]) {
//        
//        //[self.delegate ShangHomeTableViewCellClick:indexPath];
//    }
   
}


- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
